<?php
require "parts/_header.php";
require "controllers/tableEditController.php";
?>
<!--Крошки-->
<!--Крошки-->
<div id="breadcrumbs">
<a href="/admin/databaseList.php">Базы данных</a>>
<a href="/admin/databaseDetail.php?dbName=<?= $dbName ?>"><?= $dbName ?></a>>
<a href="/admin/tableDetail.php?dbTableName=<?=$dbTableName?>&dbName=<?=$dbName?>"><?=$dbTableName?></a>
</div>
<form method="POST">
    <table border="1" cellspacing="0" id="tableAddField">
        <tr>
            <th>Имя поля</th>
            <th>Тип</th>
            <th>Размер</th>
            <th>UNSIGNED</th>                
            <th>ZEROFILL</th>
            <th>NOT NULL</th>
            <th>UNIQUE</th>
            <th>AUTOINCREMENT</th>
            <th>PRIMARY KEY</th>
        </tr>

        <?php foreach ($aFields as $field) : ?>
            <?php $attribute = $aAttributes[$field['Field']]; ?>
            <tr>
                <td><input name="<?= $field['Field'] ?>[fieldName]" value="<?php echo $field['Field'] ?>"/></td>
                <td>                     
                    <select id="fieldType" name="<?= $field['Field'] ?>[fieldType]">

                        <option <?php if ($attribute['type'] == "tinyint")
            echo "selected" ?> value="TINYINT">TINYINT</option>
                        <option <?php if ($attribute['type'] == "smallint")
                        echo "selected" ?> value="SMALLINT">SMALLINT</option>
                        <option <?php if ($attribute['type'] == "int")
                        echo "selected" ?> value="INTEGER">INTEGER</option>
                        <option <?php if ($attribute['type'] == "double")
                        echo "selected" ?> value="DOUBLE">DOUBLE</option>
                        <option <?php if ($attribute['type'] == "datetime")
                        echo "selected" ?> value="DATETIME">DATETIME</option>
                        <option <?php if ($attribute['type'] == "timestamp")
                        echo "selected" ?> value="TIMESTAMP">TIMESTAMP</option> 
                        <option <?php if ($attribute['type'] == "string")
                        echo "selected" ?> value="VARCHAR">VARCHAR</option>
                        <option <?php if ($attribute['type'] == "blob")
                        echo "selected" ?> value="BLOB">BLOB</option>
                        <option <?php if ($attribute['type'] == "tinytext")
                        echo "selected" ?> value="TINYTEXT">TINYTEXT</option>
                        <option <?php if ($attribute['type'] == "text")
                        echo "selected" ?> value="TEXT">TEXT</option>
                        <option <?php if ($attribute['type'] == "longtext")
                        echo "selected" ?> value="LONGTEXT">LONGTEXT</option>
                        <option <?php if ($attribute['type'] == "boolean")
                        echo "selected" ?> value="BOOLEAN">BOOLEAN</option>
                    </select> 
                </td>
                <td>
                    <input name="<?= $field['Field'] ?>[size]" value="<?php echo $attribute['size'] ?>"/>
                </td>
                <td>
                    <input type="checkbox" name="<?= $field['Field'] ?>[unsigned]" <?php echo $attribute['unsigned'] ? 'checked' : '' ?>/>
                </td>                    
                <td>
                    <input type="checkbox" name="<?= $field['Field'] ?>[zerofill]" <?php echo $attribute['zerofill'] ? 'checked' : '' ?>/>
                </td>
                <td>
                    <input type="checkbox" name="<?= $field['Field'] ?>[not_null]" <?php echo $attribute['not_null'] ? 'checked' : '' ?>/>
                </td>
                <td>
                    <input type="checkbox" name="<?= $field['Field'] ?>[unique_key]" <?php echo $attribute['unique_key'] ? 'checked' : '' ?>/>
                </td>
                <td>
                    <input type="checkbox" name="<?= $field['Field'] ?>[auto_increment]" <?php echo $attribute['auto_increment'] ? 'checked' : '' ?>/>                        
                </td>
                <td>
                    <input type="checkbox" name="<?= $field['Field'] ?>[primary_key]" <?php echo $attribute['primary_key'] ? 'checked' : '' ?>/>                        
                </td>
            </tr>
        <?php endforeach; ?> 
    </table> 
    <input type="hidden" name="dbTableName" value="<?= $dbTableName ?>"/>
    <input type="hidden" name="dbName" value="<?= $dbName ?>"/>
    <input class="button" type="submit" name="change" value="CHANGE"/>   
</form>

<?php //вывод результата запроса?>
<?php foreach ($aResult as $result) : ?>
<?php //вывод результата обнавления?>
    <?php echo $result['main']; ?>
<?php //вывод результата обнавления первичного ключа?>
    <?php if (isset($result['primary']))
        echo $result['primary'] ?>
<?php endforeach; ?>    

<?php require "parts/_footer.php" ?>